import queue
from multiprocessing.managers import BaseManager


class QManager(BaseManager):
    pass


if __name__ == '__main__':
    # 注册队列名称
    QManager.register('get_task')
    QManager.register('get_result')

    # 连接远端manager
    m = QManager(address=('localhost', 13258), authkey=b'hello')
    m.connect()  # 连接

    task_q: queue.Queue = m.get_task()
    task_result_q: queue.Queue = m.get_result()
    print(task_q, task_result_q, task_q.empty(), task_result_q.empty())
    for i in range(10):
        try:
            n = task_q.get(timeout=5)
            task_result_q.put(n * 2)
            print(f'Get task: {n}, set result: {n * 2}')
        except queue.Empty:
            print('Task queue empty.')

    print('Slave exit.')
